<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <button @click="isShow = !isShow">{{isShow?'隐藏':'显示'}}</button>
    <keep-alive>
      <father-page v-if="isShow"></father-page>
    </keep-alive>
    
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data(){
        return {
          isShow: true
        }
      }
    });
    const FatherPage = {
      template: `
        <div>
          <h2>这是组件1</h2>  
          <input type="text" v-model="msg"/>
          {{msg}}
          <hr/>
          <input type="text" v-model="msg2"/>
          {{msg2}}
        </div>
      `,
      data(){
        return {
          msg: '',
          msg2: '' 
        }
      },
      mounted () {
        console.log('组件初始化完成');
      },
      beforeUnmount() {
        console.log('组件马上卸载');
      },
      activated() {
        console.log('组件再一次使用了')
      },
      deactivated() {
        console.log('组件停止使用了')
      },
    }
    app.component('FatherPage', FatherPage)

    app.mount('#app')
  </script>
</body>
</html>